define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'addfamily/jiaru/index' + location.search,
                    add_url: 'addfamily/jiaru/add',
                    edit_url: 'addfamily/jiaru/edit',
                    del_url: 'addfamily/jiaru/del',
                    multi_url: 'addfamily/jiaru/multi',
                    import_url: 'addfamily/jiaru/import',
                    table: 'jiaru_home',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'number', title: __('Number'), operate: 'LIKE' },
                        { field: 'home_name', title: __('Home_name'), operate: 'LIKE' },
                        { field: 'home_ad_id', title: __('Home_ad_id') },
                        { field: 'home_admin', title: __('Home_admin'), operate: 'LIKE' },
                        { field: 'home_size', title: __('Home_size') },
                        { field: 'home_image', title: __('Home_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'home_assets', title: __('Home_assets') },
                        { field: 'add_time', title: __('Add_time'), operate: 'LIKE' },
                        //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
                        {
                            field: 'operate',
                            width: "150px",
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    title: __('发送Ajax'),
                                    classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    text:"选择",
                                    confirm: '确认加入家庭吗？',
                                    url: 'addfamily/jiaru/jiaru',
                                    success: function (data, ret) {
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        // //如果需要阻止成功提示，则必须使用return false;
                                        // //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons,
                        },


                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
